package com.ztgf.message.api.client;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.ztgf.common.constant.Result;
import com.ztgf.common.enums.CodeEnum;
import com.ztgf.message.model.bo.MessageNoticeBO;
import com.ztgf.message.model.dto.MessageNoticeDTO;
import com.ztgf.message.model.service.IMessageNoticeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 公告消息控制器
 *
 * @author YUE
 * @Date 2020-05-28 16:21:07
 */

@RestController
@RequestMapping("/api/messageNotice")
@Slf4j
@Api(value = "MessageNoticeApiController",tags = "公告消息Api接口")
public class MessageNoticeApiController {

    @DubboReference
    private IMessageNoticeService messageNoticeService;

    @PostMapping("/get")
    @ApiOperation(value = "根据id查找",notes = "根据id查找")
    @ApiImplicitParam(name = "id",value = "id",required = true,paramType = "query", dataType = "Long")
    public Result<MessageNoticeDTO> get(@RequestParam("id") Long id){
        if(id == null){
            return new Result<>(CodeEnum.FAIL_100002 );
        }
        MessageNoticeDTO dto = messageNoticeService.selectById(id);
        return new Result<>(dto);
    }

    @ApiOperation(value = "公告消息列表",notes = "公告消息列表")
    @PostMapping("/queryPageList")
    public Result<Page<MessageNoticeDTO>> queryPageList(MessageNoticeBO messageNoticeBO){
        Page<MessageNoticeDTO> epgNoticeDTOPage = messageNoticeService.getBySelectNoticeInfoPage(messageNoticeBO);
        return new Result<>(epgNoticeDTOPage);
    }

    @ApiOperation(value = "置顶公告",notes = "置顶公告")
    @PostMapping("/getTopNotice")
    public Result<MessageNoticeDTO> getTopNotice(){
        Wrapper<MessageNoticeDTO> wrapper = new EntityWrapper<>();
        wrapper.eq("is_top", 0);
        wrapper.eq("deleted", 0);
        MessageNoticeDTO messageNoticeDTO = messageNoticeService.selectOne(wrapper);
        return new Result<>(messageNoticeDTO);
    }
}
